<?php
/**
 * Created by PhpStorm.
 * User: u
 * Date: 2018/12/3
 * Time: 15:27
 */

namespace app\controllers;

use common\widgets\Tool;
use Yii;

class MemberController extends BaseController
{
    /** @var \common\logics\member\MemberLogic $MemberService ***/
    private $MemberService;

    public function init()
    {
        $this->MemberService = Yii::$container->get("MemberService");
         parent::init();
    }

    public function actionList()
    {
        $input = [
            'role' => intval(Yii::$app->request->post('role',0)),      //用户角色 1.买手，2.商家
            'search_type' => Yii::$app->request->post('search_type',0),//搜索类型 1.注册账号,2.邀请人手机，3.qq号，4.微信号 5.绑定买号
            'name' => Yii::$app->request->post('name',''),              // 注册账号,邀请人账号， qq号   微信号
            'page' => Yii::$app->request->post('page',1),           //当前页数
            'limit' => Yii::$app->request->post('limit',10),                 //当前总记录条数
        ];
        //获取列表
        $list = $this->MemberService->getList($input);
        return $list;
    }
    //查看绑定商家或者买手账户信息
    public function actionGetBuyerMerchant()
    {
        $param = [
            'b_id' => Yii::$app->request->post('b_id',0),//买手或者商家id
            'role' => Yii::$app->request->post('role',0),//会员角色，1.买手，2商家
        ];
        $result = $this->MemberService->getBuyers($param);
        return $result;
    }
    //修改手机号码
    public function actionModifyPhone()
    {
        $param = [
            "buy_id" => Yii::$app->request->post("buy_id"),
            "old_phone" => Yii::$app->request->post('old_phone'),
            "new_phone" => Yii::$app->request->post('new_phone'),
            "confirm_phone" =>Yii::$app->request->post("confirm_phone"),
            'sys_code' => Yii::$app->request->post('sys_code',''),// 钉钉验证码
            'phone' => Yii::$app->request->post('phone',''),//操作人手机号
        ];
        $result = $this->MemberService->modifyPhone($param);
        return $result;
    }
    //修改买号绑定淘宝天猫
    public function actionModifyMember()
    {
        $param = [
            "t_id" => Yii::$app->request->post('t_id'),
            "tbname" => Yii::$app->request->post("tbname"),
            'sys_code' => Yii::$app->request->post('sys_code',''),// 钉钉验证码
            'phone' => Yii::$app->request->post('phone',''),//操作人手机号
        ];
        $result = $this->MemberService->modifyTbName($param);
        return $result;
    }
    //删除买号
    public function actionDelMember()
    {
        $param = [
            "t_id" => Yii::$app->request->post('t_id'),
            'sys_code' => Yii::$app->request->post('sys_code',''),// 钉钉验证码
            'phone' => Yii::$app->request->post('phone',''),//操作人手机号
        ];
        $result = $this->MemberService->delMember($param);
        return $result;
    }
    //会员管理显示隐藏
    public function actionIsCover()
    {
        $param = [
            'buy_id' => Yii::$app->request->post('buy_id',0),//买手或者商家id
            'o_id' => Yii::$app->request->post('o_id',0), //绑定id 绑定淘宝id 或者绑定店铺id
            'role' => Yii::$app->request->post('role',1), //用户角色 1.买手， 2.商家
            'display' => Yii::$app->request->post('display',1),// 1.显示,0 隐藏
            'sys_code' => Yii::$app->request->post('sys_code',''),// 钉钉验证码
            'phone' => Yii::$app->request->post('phone',''),//操作人手机号
        ];
        $result = $this->MemberService->getDisplay($param);
        return $result;
    }

    //修改手机地址
    public function actionModifyReceiveAddr()
    {
        $param = [
            't_id' => Yii::$app->request->post("t_id"),
            "takename" => Yii::$app->request->post("takename"),
            "pro_name" => Yii::$app->request->post("pro_name"),
            "pro_code" => Yii::$app->request->post("pro_code"),
            "city_name" => Yii::$app->request->post("city_name"),
            "city_code" => Yii::$app->request->post("city_code"),
            "area_name" => Yii::$app->request->post("area_name"),
            "area_code" => Yii::$app->request->post("area_code"),
            "addr" => Yii::$app->request->post("addr"),
            "takephone" => Yii::$app->request->post("takephone"),
            'sys_code' => Yii::$app->request->post('sys_code',''),// 钉钉验证码
            'phone' => Yii::$app->request->post('phone',''),//操作人手机号
        ];
        $result = $this->MemberService->modifyAreaAddr($param);
        return $result;
    }

    //修改性别
    public function actionModifySex()
    {
        $param = [
            'buy_id' => Yii::$app->request->post('buy_id',0),//买手或者商家id
            'o_id' => Yii::$app->request->post('o_id',0),//绑定id
            "sex" => Yii::$app->request->post("sex",""),//性别
            'sys_code' => Yii::$app->request->post('sys_code',''),// 钉钉验证码
            'phone' => Yii::$app->request->post('phone',''),//操作人手机号
        ];
        $result = $this->MemberService->modifySex($param);
        return $result;
    }

    //修改可接任务数量
    public function actionModifyAccessTask()
    {
        $param = [
            't_id' => Yii::$app->request->post('t_id',0), //买手或者商家id
            'num' =>  Yii::$app->request->post('num',0), //可接任务数
            'sys_code' => Yii::$app->request->post('sys_code',''),// 钉钉验证码
            'phone' => Yii::$app->request->post('phone',''),//操作人手机号
        ];
        $result = $this->MemberService->modifyAccessTask($param);
        return $result;
    }
    //搜索商家或者买手
    public function actionGetSignMember()
    {
        $param = [
            'role' => intval(Yii::$app->request->post('role','')),      //用户角色 1.买手，2.商家
            'search' => Yii::$app->request->post('search',''),//搜索手机号
        ];
        //搜索单个会员
        $result = $this->MemberService->getSignMember($param);
        return $result;
    }
    //设置会员过期时间
    public function actionModifyExpireTime()
    {
        $param = [
            'buy_id' => intval(Yii::$app->request->post('buy_id','')),      //用户id
            'expire_time' => Yii::$app->request->post('expire_time',''),//过期时间
            'description' => Yii::$app->request->post('description',''),//备注
            'imgUrl' => Yii::$app->request->post('imgUrl',''),//截图url
            'admin_id' => Yii::$app->request->post('admin_id',''),//操作人id
            'sys_code' => Yii::$app->request->post('sys_code',''),// 钉钉验证码
            'phone' => Yii::$app->request->post('phone',''),//操作人手机号
            'operator_name' => Yii::$app->request->post('operator_name',''),//操作人姓名
        ];
        $result = $this->MemberService->modifyExpireTime($param);
        return $result;
    }

    //查询修改过期时间日志
    public function actionModifyExpireLog()
    {
        $param = [
            'role' => intval(Yii::$app->request->post('role','')),      //用户角色 1.买手，2.商家
            'search' => Yii::$app->request->post('search',''),//搜索手机号
            'begin_time' => Yii::$app->request->post('begin_time',''),//搜索开始时间
            'end_time' => Yii::$app->request->post('end_time',''),//结束时间
        ];
        if (!empty($param['begin_time'])) {
            $param['begin_time'] = date("Y-m-d H:i:s",$param['begin_time']);
        }
        if (!empty($param['end_time'])) {
            $param['end_time'] = date("Y-m-d H:i:s",$param['end_time']);
        }
        $result = $this->MemberService->modifyExpireLog($param);
        return $result;
    }

    //修改开户名
    public function actionModifyBankName() {
        $param = [
          'id' =>   Yii::$app->request->post('id',''),//账户id
          'name' => Yii::$app->request->post('name',''),//姓名
        ];
        $result = $this->MemberService->ModifyBankName($param);
        return $result;
    }

    //账户审核
   public function actionAuditUserBank() {
       $param = [
           'id' =>   Yii::$app->request->post('id',''),//账户id
           'audit_status' => Yii::$app->request->post('audit_status',''),// 审核状态 1 待审核 2 审核通过，3审核不通过
           'operator' => Yii::$app->request->post('operator',''),//操作人
           'audit_operator' => Yii::$app->request->post('audit_operator',''),//操作人手机号
           'reason' => Yii::$app->request->post('reason',''),//不通过原因
           'refuse_plat' => Yii::$app->request->post('refuse_plat',''),//不通过平台
       ];
       $result = $this->MemberService->AuditUserBank($param);
       return $result;
   }

   //修改银行卡号
    public function actionModifyBankNum() {
        $param = [
            'id' =>   Yii::$app->request->post('id',''),//账户id
            'cardno' => Yii::$app->request->post('cardno',''),// 银行卡号
        ];
        $result = $this->MemberService->ModifyBankNum($param);
        return $result;
    }

   //会员黑名单列表
    public function actionUserBlackList() {
        $param = [
            'userId' =>   Yii::$app->request->post('userId',''),//会员id
            'page_num' => Yii::$app->request->post('page_num',1),           //当前页数
            'limit' => Yii::$app->request->post('limit',10),                 //当前总记录条数
        ];
        $result = $this->MemberService->UserBlackList($param);
        return $result;
    }

    //添加黑名单会员
    public function actionAddBlackUser() {
        $param = [
            'userId' =>   Yii::$app->request->post('userId',0),//会员id
            'freeze_status' => Yii::$app->request->post('freeze_status',1),//黑名单类型
            'freeze_reason' => Yii::$app->request->post('freeze_reason',''),//黑名单原因
            'freeze_operator' => Yii::$app->request->post('freeze_operator',''),//冻结操作人
        ];
        $result = $this->MemberService->AddBlackUser($param);
        return $result;
    }

    //qq群超链接
    public function actionQqUrl() {
        $qq_url = Yii::$app->request->post('qq_url','');//qq群超链接
        $addRedis = Yii::$app->cache->set('qq_url',$qq_url);
        if ($addRedis) {
            return Tool::returnJson([],200,'成功');
        }
        return Tool::returnJson([],409,'失败');
    }

    //会员提现账户审核
    public function actionUserBankList() {
        $param = [
          'status' => Yii::$app->request->post('status',''),// 审核状态 1 待审核 2 审核通过，3审核不通过
          'search_type' => Yii::$app->request->post('search_type',''),//1-买手id，2-开户名，3-支付宝卡号，4-财付通卡号，5-银行卡号，6-身份证号
          'value' => Yii::$app->request->post('value',''),//输入框值
        ];
        $result = $this->MemberService->UserBankList($param);
        return $result;
    }


    //买手明细查询 TODO::未完成
	public function actionUserDetailed() {
		$param  = [
			'status'      => Yii::$app->request->post('status', ''),// 审核状态 1 待审核 2 审核通过，3审核不通过
			'search_type' => Yii::$app->request->post('search_type', ''),//1-买手id，2-开户名，3-支付宝卡号，4-财付通卡号，5-银行卡号，6-身份证号
			'value'       => Yii::$app->request->post('value', ''),//输入框值
		];
		$result = $this->MemberService->UserBankList($param);
		return $result;
	}

	/**
	 * actionUserExport 商家根据订单状态导出
	 * @author 中崋 (1291713293@qq.com)
	 * @date   2019/5/20
	 * @return array
	 */
	public function actionUserExport() {
		$param  = [
			'day_num'      => Yii::$app->request->get('day_num', 7),
			'order_status' => Yii::$app->request->get('order_status', 4),
		];
		$result = $this->MemberService->userExport($param);
		return $result;
	}

}